#include <stdio.h>
#include <conio.h>
#include <time.h>
#include <Windows.h>
#include "Game.h"
#include "Useful_Functions.h"

int main(int argc, char ** argv)
{
	myClass mine;
	mine.myVal = 7;
	printf("My Value is: %d", mine.myVal);
	//remove console cursor
	CONSOLE_CURSOR_INFO cursor_data;
	cursor_data.bVisible = false;
	cursor_data.dwSize = 1;
	SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &cursor_data);
	
	//Resize the console
	HWND console = GetConsoleWindow();
	RECT r;
	GetWindowRect(console, &r);	//Store the console's current dimensions
	MoveWindow(console, 0, 0, 1080, 600, TRUE);

	//Seed the RNG
	srand((unsigned int)time(NULL));


	//initialization
	Game g;
	bool running = true;
	time_t timer, then = clock(), now, passed;
	int input = ' ';
	//game loop
	while (running)
	{
		// input
		if (_kbhit())
		{
			input = _getch();
			if (input == 'q')
				return 1;
			g.handleInput(input);
		}
		else
		{
			// calculate the passage of time
			now = clock();
			passed = now - then;
			then = now;

			// logic
			g.update((int)passed);

			// draw
			g.draw();
			if(g.checkWin()){break;}

			//Throttle Code
			timer = clock() + 200;
			while (!_kbhit() && clock() < timer)
			{
				Sleep(1);
			}
		}
	}
	return 0;
}